package com.qf.controllr;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.controllr
 * @Description:
 * @Date 2022/10/1 19:04
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/user/findAll")
    public List<User> findAll(){
        List<User> all = userService.findAll();
        return all;
    }

    @RequestMapping("/users")
    public ModelAndView paug(
            ModelAndView view,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",required = false ,defaultValue = "3")Integer pageSize){

        PageInfo<User> page = userService.findByPage(pageNum,pageSize);
        view.addObject("data", page);
        view.setViewName("forward:/list.jsp");
        return view;
    }
}
